package com.legal.aid.system.controller;

import com.legal.aid.common.annotation.Log;
import com.legal.aid.common.core.controller.BaseController;
import com.legal.aid.common.core.domain.AjaxResult;
import com.legal.aid.common.core.page.TableDataInfo;
import com.legal.aid.common.enums.BusinessType;
import com.legal.aid.common.utils.poi.ExcelUtil;
import com.legal.aid.system.domain.Lawyer;
import com.legal.aid.system.service.ILawyerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 律师信息Controller
 * 
 * @author ruoyi
 * @date 2025-05-23
 */
@RestController
@RequestMapping("/system/lawyer")
public class LawyerController extends BaseController
{
    @Autowired
    private ILawyerService lawyerService;

    /**
     * 查询律师信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:lawyer:list')")
    @GetMapping("/list")
    public TableDataInfo list(Lawyer lawyer)
    {
        startPage();
        List<Lawyer> list = lawyerService.selectLawyerList(lawyer);
        return getDataTable(list);
    }

    /**
     * 导出律师信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:lawyer:export')")
    @Log(title = "律师信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Lawyer lawyer)
    {
        List<Lawyer> list = lawyerService.selectLawyerList(lawyer);
        ExcelUtil<Lawyer> util = new ExcelUtil<Lawyer>(Lawyer.class);
        util.exportExcel(response, list, "律师信息数据");
    }

    /**
     * 获取律师信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:lawyer:query')")
    @GetMapping(value = "/{lawyerId}")
    public AjaxResult getInfo(@PathVariable("lawyerId") Long lawyerId)
    {
        return success(lawyerService.selectLawyerByLawyerId(lawyerId));
    }

    /**
     * 获取律师信息详细信息和基本信息
     */
    @PreAuthorize("@ss.hasPermi('system:lawyer:query')")
    @GetMapping(value = "/details/{lawyerId}")
    public AjaxResult getLawyerBaseInfo(@PathVariable("lawyerId") Long lawyerId)
    {
        return success(lawyerService.selectLawyerBaseInfoByLawyerId(lawyerId));
    }

    /**
     * 新增律师信息
     */
    @PreAuthorize("@ss.hasPermi('system:lawyer:add')")
    @Log(title = "律师信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Lawyer lawyer)
    {
        return toAjax(lawyerService.insertLawyer(lawyer));
    }

    /**
     * 修改律师信息
     */
    @PreAuthorize("@ss.hasPermi('system:lawyer:edit')")
    @Log(title = "律师信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Lawyer lawyer)
    {
        return toAjax(lawyerService.updateLawyer(lawyer));
    }

    /**
     * 删除律师信息
     */
    @PreAuthorize("@ss.hasPermi('system:lawyer:remove')")
    @Log(title = "律师信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{lawyerIds}")
    public AjaxResult remove(@PathVariable Long[] lawyerIds)
    {
        return toAjax(lawyerService.deleteLawyerByLawyerIds(lawyerIds));
    }
}
